<template>
    <div class="w750">
        <van-overlay :show="loadOrder">
            <div class="flex-center bg-fff center-xy rounded-4" style="width: 120px; height: 120px">
                <van-loading :color="themes.color" :text-color="themes.color" vertical>加载中...</van-loading>
            </div>
        </van-overlay>
        <div :class="themes.theme" :style="{ '--themescolor': themes.color }">
            <div class="submit-order">
                <!-- 选择配送方式 -->
                <div v-if="result.deliveryTypeList && result.deliveryTypeList.length > 1" class="bg-fff d-flex font-14 a-center mb-1 p-1 j-sb" style="border-radius: 0 0 12px 12px">
                    <div class="mr-2">配送方式</div>
                    <div class="d-flex flex-end bg-eee rounded-15 position-relative" style="padding: 5px 12px">
                        <span
                            :class="[result.deliveryTypeList.length == 2 && index == 0 ? 'mr-2' : '']"
                            v-for="(delivery, index) in result.deliveryTypeList"
                            :key="index"
                            @click="changeDeliverMode(delivery)"
                        >
                            {{ delivery.deliveryType == 'merchantDelivery' ? '商家配送' : '到店自提' }}
                        </span>
                        <span
                            class="position-absolute h-100 top-0 bg-main rounded-15 flex-center text-fff transition-all05"
                            :style="{
                                width: result.deliveryTypeList && result.deliveryTypeList.length == 1 ? '100%' : '50%',
                                left:
                                    result.deliveryTypeList && result.deliveryTypeList.length == 1
                                        ? '0%'
                                        : result.deliveryTypeList && result.deliveryTypeList.length == 2 && deliveryMode == 'merchantDelivery'
                                        ? '0'
                                        : '50%'
                            }"
                        >
                            {{ deliveryMode == 'merchantDelivery' ? '商家配送' : '到店自提' }}
                        </span>
                    </div>
                </div>
                <!-- 自提点选择 -->
                <template v-if="deliveryMode == 'sinceMention'">
                    <!-- 没有自提点 -->
                    <div v-if="!point" class="bg-fff p-1 border-bottom-10bg rounded-12 font-14">
                        <div class="d-flex">
                            <div class="mr-1">自提点</div>
                            <div class="flex-1 text-right" @click="toSelectPoint">
                                <span v-if="!point">请选择</span>
                                <span v-else>{{ point.pointName }} {{ point.sinceMentionDetailAddr }}</span>
                                <span class="iconfont iconArrowRight" style="font-size: 14px; color: #c0c4d6"></span>
                            </div>
                        </div>
                    </div>
                    <!-- 存在自提点 -->
                    <div v-else class="bg-fff p-1 border-bottom-10bg rounded-12 font-14">
                        <div class="d-flex">
                            <div class="mr-1 font-16 font-weight">自提点：{{ point.pointName }}</div>
                            <div class="flex-1 text-right" @click="toSelectPoint">
                                <span>切换</span>
                                <span class="iconfont iconArrowRight" style="font-size: 14px; color: #c0c4d6"></span>
                            </div>
                        </div>
                        <div class="font-12 mt-1">{{ point.sinceMentionDetailAddr }}</div>
                        <div class="font-12 text-999 mt-1">
                            <div>营业时间：{{ point.periodJoin }}</div>
                            <div class="mt">
                                <span class="pr" v-for="(time, index) in point.businessHoursList" :key="index">{{ time.begin }}~{{ time.end }}</span>
                            </div>
                        </div>
                    </div>

                    <div @click="showDialog" class="bg-fff p-1 rounded-12 font-14">
                        <div class="d-flex">
                            <div class="mr-1">提货人：</div>
                            <div class="flex-1 d-flex j-sb">
                                <div class="flex-1 line-clamp1" style="width: auto; max-width: 4rem">
                                    <span class="mr-1">{{ contextPerson }}</span>
                                    <span>{{ phone }}</span>
                                </div>
                                <div>
                                    <span>{{ !(contextPerson && phone) ? '请输入' : '修改' }}</span>
                                    <span class="iconfont iconArrowRight" style="font-size: 14px; color: #c0c4d6"></span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <van-overlay :show="showDelivery" :z-index="1000">
                        <div class="font-14 flex-center h-100">
                            <div class="bg-fff rounded-8 position-relative" style="width: 80%; height: 240px">
                                <div
                                    @click="closeDialog"
                                    class="iconfont iconclose position-absolute text-ccc"
                                    style="font-size: 14px; right: 10px; top: 10px"
                                />
                                <div class="font-16 p-1 text-center">提货人信息</div>
                                <div class="p-1">
                                    <div class="d-flex border-bottom" style="padding: 12px 10px">
                                        <span style="flex: 0 0 80px">提货人</span>
                                        <input v-model="formContextPerson" class="flex-1" type="text" placeholder="请输入提货人" />
                                    </div>
                                    <div class="d-flex border-bottom" style="padding: 12px 10px">
                                        <span style="flex: 0 0 80px">手机号</span>
                                        <input v-model="formPhone" class="flex-1" type="text" placeholder="请输入手机号" />
                                    </div>
                                </div>
                                <div @click="submitInfo" class="m-2 py-1 rounded-8 text-center text-fff bg-main">
                                    <span>确定</span>
                                </div>
                            </div>
                        </div>
                    </van-overlay>
                </template>

                <!-- 收货地址 -->
                <template v-else>
                    <template v-if="result.userAddress">
                        <div class="order-address">
                            <div @click="goAddress">
                                <div class="user-info">
									<span class="iconfont iconlocation img" style="font-size: 16px;"></span>
                                    <em class="item">{{ result.userAddress.receiver }}</em>
                                    <em class="item">{{ result.userAddress.mobile }}</em>
                                </div>
                                <div class="address-det" style="margin: 0">
                                    {{ result.userAddress.province }} {{ result.userAddress.city }} {{ result.userAddress.area }}
                                    {{ result.userAddress.subAdds }}
                                </div>
                                <i class="arr"><img src="@/assets/images/arrow.png" alt="" /></i>
                            </div>
                        </div>
                    </template>

                    <template v-if="!result.userAddress">
                        <div class="order-address">
                            <div @click="goAddress">
                                <div class="user-info">
									<span class="iconfont iconlocation img" style="font-size: 14px;"></span>
                                    <em class="item">请添加收货地址</em>
                                    <em class="item"></em>
                                </div>
                                <div class="address-det"></div>
                                <i class="arr"><img src="@/assets/images/arrow.png" alt="" /></i>
                            </div>
                        </div>
                    </template>
                </template>

                <template v-if="result.assemblyOrderType == 'OVERSEAS'">
                    <div class="order-address" @click.stop="goIdentity" style="background: #fff; margin: 10px 0; padding: 0 24px 5px 10px">
                        <div class="user-info" style="padding: 10px 0px 5px">
                            <em class="item">身份信息</em>
                            <em class="item">{{ !overseasUserInfo.realName ? '请填写相关海淘用户信息' : overseasUserInfo.realName }}</em>
                            <em class="item">{{ overseasUserInfo.cardNum }}</em>
                        </div>
                        <i class="arr" style="top: 40%"><img src="@/assets/images/arrow.png" alt="" style="width: 100%" /></i>
                    </div>
                </template>

                <div class="submit-list">
					<!-- 商品 -->
					<div class="submit-con total" v-for="(group, groupIndex) in result.orderGroupInfoBOS" :key="`groupCart +  ${groupIndex}`">
						<div class="py-1">
							<span class="iconfont icondianpu" style="font-size: 14px"></span>
							<span class="ml-03 font-14">{{group.groupName}}</span>
						</div>
						<!-- 未参加营销且上线的商品 -->
						<prod-info v-if="!$utils.test.isEmpty(group.enableGroupCartList)" :list="group.enableGroupCartList" :num="group.prodNum" type="enableGroup" :groupIndex="groupIndex" @openGoodsPopup="openGoodsPopup"></prod-info>
						<!-- 活动商品项 -->
						<div v-for="(promotionItem, promotionIndex) in group.promotionGroupCartList" :key="'promotionItem' + promotionIndex" class="promotion-goods" :class="{first:!$utils.test.isEmpty(group.enableGroupCartList)}">
							<div v-if="group.prodSource != 'JD'" class="promotion-item">
							    <i class="pro-i" style="color: #fff" :style="{ background: themes.color }">满减</i>
							    <span class="pro-span line-clamp1">{{promotionItem.description}}</span>
							</div>
							<prod-info v-if="promotionItem.hitCartItems" :list="promotionItem.hitCartItems" :num="promotionItem.prodNum" type="promotion" :groupIndex="groupIndex" :promotionIndex="promotionIndex"  @openGoodsPopup="openGoodsPopup"></prod-info>
							<!-- <div class="promotions bg-f8 rounded-12 overflow-h" v-if="group.prodSource == 'JD'">
								<template>
									<div class="promotions-item flex-between h-60p font-12 px-1 py-05p"  v-for="(presentItem,presentIndex) in promotionItem.presents" v-if="promotionItem.isShowAllPresents || presentIndex === 0" :key="'presentIndex' + presentIndex">
										<div class="flex-start flex-1">
											<div class="w-50p h-50p rounded-6 overflow-h">
												 <legend-image :pic="presentItem.pic" :options="{ w: '50', h: '50' }" :isJD="group.prodSource == 'JD'" class="w-100 h-100" />
											</div>
											<div class="flex-1 w-0 ml-1">
												<div class="font-12 line-clamp1">{{presentItem.name}}</div>
												<div class="font-10 mt-04 bg-e0 rounded-8 text-fff px-05p d-inline-block">赠品</div>
											</div>
										</div>
									</div>
									<div v-if="promotionItem.limitNumber > 1 && promotionItem.presents.length > 1" class="h-20p flex-center" @click="setIsShowAllPresents(groupIndex,promotionIndex)">
										<span :style="{transform: `rotateX(${promotionItem.isShowAllPresents ? 180 : 0}deg)`}" class="icon iconfont iconxiangxia" style="font-size: 12px;"></span>
									</div>
								</template>
							</div> -->
							<div class="promotions bg-f8 rounded-12 overflow-h">
								<div v-if="promotionItem.flag" class="promotions-item flex-between bg-f8 px-1 py-05p h-60p font-12">
									<div>商品已满足满赠条件，可挑选心仪的赠品</div>
									<div class="btn" @click="openPresents(groupIndex,promotionIndex)">挑选赠品</div>
								</div>
								<div class="promotions-item flex-between h-60p font-12 px-1 py-05p"  v-for="(presentItem,presentIndex) in promotionItem.outPresents" :key="'outPresentIndex' + presentIndex">
									<div class="flex-start flex-1">
										<div class="w-50p h-50p rounded-6 overflow-h">
											 <legend-image :pic="presentItem.pic" :options="{ w: '50', h: '50' }" :isJD="presentItem.outPresent" class="w-100 h-100" />
										</div>
										<div class="flex-1 w-0 ml-1">
											<div class="font-12 line-clamp1">{{presentItem.name}}</div>
											<div class="font-10 mt-04 bg-e0 rounded-8 text-fff px-05p d-inline-block">京东赠品</div>
										</div>
									</div>
									<!-- outPresent为true时是外部供应商 如 京东 -->
									<div v-if="!presentItem.outPresent" class="btn" @click="openPresents(groupIndex,promotionIndex)">重新选择</div>
								</div>
								<template v-if="!promotionItem.flag">
									<div class="promotions-item flex-between h-60p font-12 px-1 py-05p"  v-for="(presentItem,presentIndex) in promotionItem.selPresents" v-if="promotionItem.isShowAllPresents || presentIndex === 0" :key="'presentIndex' + presentIndex">
										<div class="flex-start flex-1">
											<div class="w-50p h-50p rounded-6 overflow-h">
												 <legend-image :pic="presentItem.pic" :options="{ w: '50', h: '50' }" :isJD="presentItem.outPresent" class="w-100 h-100" />
											</div>
											<div class="flex-1 w-0 ml-1">
												<div class="font-12 line-clamp1">{{presentItem.name}}</div>
												<div class="font-10 mt-04 bg-e0 rounded-8 text-fff px-05p d-inline-block">赠品</div>
											</div>
										</div>
										<!-- outPresent为true时是外部供应商 如 京东 -->
										<div v-if="presentIndex === 0" class="btn" @click="openPresents(groupIndex,promotionIndex)">重新选择</div>
									</div>
									<div v-if="promotionItem.limitNumber > 1 && promotionItem.selPresents.length > 1" class="h-20p flex-center" @click="setIsShowAllPresents(groupIndex,promotionIndex)">
										<span :style="{transform: `rotateX(${promotionItem.isShowAllPresents ? 180 : 0}deg)`}" class="icon iconfont iconxiangxia" style="font-size: 12px;"></span>
									</div>
								</template>
							</div>
						</div>
						<div>
							<div class="order-style">
							    <span class="left">配送运费</span>
							    <span class="right">
							        <span class="price text-333">
							            &#65509;
							            <em class="now text-333">{{ Money(group.groupFreightAmount)[0] }}</em>
							            .{{ Money(group.groupFreightAmount)[1] }}
							        </span>
							    </span>
							</div>
							<div class="order-style">
							    <span class="right">
											<span>合计：</span>
							        <span class="price">
							            &#65509;
							            <em class="now">{{ Money(group.groupOrderActualTotal)[0] }}</em>
							            .{{ Money(group.groupOrderActualTotal)[1] }}
							        </span>
							    </span>
							</div>
						</div>
					</div>
                  
                    <div class="submit-con">
                        <div class="order-style bt">
                            <span class="left">买家留言</span>
                            <span class="right words"><input type="text" v-model="remark" style="font-size: 14px" placeholder="给卖家留言" @focus="getFocus" /></span>
                        </div>

                        <div class="order-style bt" @click="goInvoice" v-if="result.supportInvoice">
                            <span class="left">开具发票</span>
                            <span class="right">
                                <em class="right-em" v-if="invoiceInfo">
                                    {{ invoiceTypeVal }}-明细-{{ invoiceTitle == 'ENTERPRISE' ? '企业' : '个人' }}-抬头
                                </em>
                                <em class="right-em" v-else>本次不开具发票</em>

                                <i class="arr"><img src="@/assets/images/arrow.png" alt="" /></i>
                            </span>
                        </div>
                        <div class="order-style bt sub-click" @click="changeShowCoupon" v-if="integralOrderDeductInfo.exclusiveCoupon || !checked">
                            <span class="left">
                                优惠券
                                <em class="coupon-num" :style="{ background: 'none', color: themes.color, border: `1px solid ${themes.color}` }">
                                    {{ canUseCoupon.length ? canUseCoupon.length : 0 }}张可用
                                </em>
                            </span>
                            <span class="right">
                                <em class="right-em">{{ checkedCoupon ? `-${Money(couponPrice)[0]}.${Money(couponPrice)[1]}元` : '未使用' }}</em>
                                <i class="arr"><img src="@/assets/images/arrow.png" alt="" /></i>
                            </span>
                        </div>
                        <div
                            class="order-style bt"
                            v-if="integralOrderDeductInfo.orderDeductEnable && (integralOrderDeductInfo.exclusiveCoupon || !checkedCoupon)"
                        >
                            <span class="left">使用{{ integralName }}</span>
                            <div class="right words" style="height: 22px">
                                <span class="right-em" style="margin-right: 53px">
                                    最多可用{{ integralOrderDeductInfo.availableIntegral }}{{ integralName }} ， -{{
                                        Money(integralOrderDeductInfo.deductAmount)[0]
                                    }}.{{ Money(integralOrderDeductInfo.deductAmount)[1] }}元
                                </span>
                                <div class="" style="position: absolute; right: 0; top: 0; z-index: 0;">
                                    <van-switch
                                        :value="checked"
                                        @input="changeIntegral"
                                        size="22px"
                                        :activeColor="themes.color"
                                        :disabled="integralOrderDeductInfo.deductAmount == 0"
                                    />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="submit-con total">
                        <div class="order-style">
                            <span class="left">商品金额</span>
                            <span class="right">
                                <span class="price">
                                    &#65509;
                                    <em class="now">{{ Money(result.orderTotalCash)[0] }}</em>
                                    .{{ Money(result.orderTotalCash)[1] }}
                                </span>
                            </span>
                        </div>
                        <div class="order-style" v-if="result.totalTaxes">
                            <div class="left">
                                <span>税费</span>
                                <span @click="checkDetail" class="iconfont iconquestion ml" style="font-size: 12px"></span>
                            </div>
                            <span class="right">
                                <span class="price">
                                    &#65509;
                                    <em class="now">{{ Money(result.totalTaxes)[0] }}</em>
                                    .{{ Money(result.totalTaxes)[1] }}
                                </span>
                            </span>
                        </div>
                        <div class="order-style" v-if="result.salesAmount > 0">
                            <span class="left">折扣金额</span>
                            <span class="right">
                                <span class="price">
                                    -&#65509;
                                    <em class="now">{{ Money(result.salesAmount)[0] }}</em>
                                    .{{ Money(result.salesAmount)[1] }}
                                </span>
                            </span>
                        </div>
                        <div class="order-style" v-if="result.shareSalesAmount">
                            <span class="left">分享折扣金额</span>
                            <span class="right">
                                <span class="price">
                                    -&#65509;
                                    <em class="now">{{ Money(result.shareSalesAmount)[0] }}</em>
                                    .{{ Money(result.shareSalesAmount)[1] }}
                                </span>
                            </span>
                        </div>
                        <div class="order-style" v-if="result.marketingAmount > 0">
                            <span class="left">营销金额</span>
                            <span class="right">
                                <span class="price">
                                    -&#65509;
                                    <em class="now">{{ Money(result.marketingAmount)[0] }}</em>
                                    .{{ Money(result.marketingAmount)[1] }}
                                </span>
                            </span>
                        </div>
                        <div class="order-style" v-if="result.couponOffPrice > 0">
                            <span class="left">优惠券金额</span>
                            <span class="right">
                                <span class="price">
                                    -&#65509;
                                    <em class="now">{{ Money(result.couponOffPrice)[0] }}</em>
                                    .{{ Money(result.couponOffPrice)[1] }}
                                </span>
                            </span>
                        </div>
                        <div class="order-style" v-if="checked && integralOrderDeductInfo.deductAmount > 0">
                            <span class="left">{{ integralName }}抵扣</span>
                            <span class="right">
                                <span class="price">
                                    -&#65509;
                                    <em class="now">{{ Money(checked ? integralOrderDeductInfo.deductAmount : 0)[0] }}</em>
                                    .{{ Money(checked ? integralOrderDeductInfo.deductAmount : 0)[1] }}
                                </span>
                            </span>
                        </div>
                        <div class="order-style">
                            <span class="left">配送费用</span>
                            <span class="right">
                                <span class="price">
                                    &#65509;
                                    <em class="now">{{ Money(result.orderFreightAmount)[0] }}</em>
                                    .{{ Money(result.orderFreightAmount)[1] }}
                                </span>
                            </span>
                        </div>
                    </div>
					<!-- 失效商品 -->
					<div class="mt-1 font-14 rounded-10 bg-white" v-if="result.disableCartList && result.disableCartList.length != 0">
					    <div class="p-1">失效商品</div>
					    <div class="p-1" v-for="(good, goodIndex) in result.disableCartList" :key="goodIndex">
							<div class="flex-start" :class="[goodIndex == 0?'':'border-top border-c-e4']">
								<div class="rounded-8 overflow-h position-relative" style="width: 90px;height: 90px;">
									<legend-image
										class="w-100 h-100"
										:pic="good.pic"
										:options="{ w: '180', h: '180' }"
										:isJD="good.prodSource == 'JD'"
									/>
									<div class="flex-center w-100 position-absolute left-0 bottom-0 text-white py-03p" style="background: rgba(0,0,0,0.6);">
										<span>商品失效</span>
									</div>
								</div>
					
								<div class="flex-1 pl-2 overflow-h flex-col-between" style="height: 90px;">
									<div class="line-clamp2">{{ good.prodName }}</div>
									<div>￥{{good.price}}</div>
									<span class="">{{ good.cnProperties }}</span>
									<div class="">
										<span class="text-999">该商品已失效</span>
									</div>
								</div>
							</div>
							</div>
					</div>
					
					<!-- 无法购买商品 -->
					<div class="mt-1 font-14 rounded-10 bg-white" v-if="result.limitDisableCartList && result.limitDisableCartList.length != 0">
					    <div class="p-1">无法购买商品</div>
					    <div class="p-1" v-for="(good, goodIndex) in result.limitDisableCartList" :key="goodIndex">
							<div class="flex-start" :class="[goodIndex == 0?'':'border-top border-c-e4']">
								<div class="rounded-8 overflow-h position-relative" style="width: 90px;height: 90px; cursor: pointer;" @click="goGoodsDetil(good.prodId)">
									<legend-image
										class="w-100 h-100"
										:pic="good.pic"
										:options="{ w: '180', h: '180' }"
										:isJD="good.prodSource == 'JD'"
									/>
									<div class="flex-center w-100 position-absolute left-0 bottom-0 text-white py-03p" style="background: rgba(0,0,0,0.6);">
										<span>商品失效</span>
									</div>
								</div>
					
								<div class="flex-1 pl-2 overflow-h flex-col-between" style="height: 90px;">
									<div class="line-clamp2">{{ good.prodName }}</div>
									<div>￥{{good.price}}</div>
									<span class="">{{ good.cnProperties }}</span>
									<div class="line-clamp1">
										<span class="text-danger">商品限购{{good.purchaseLimitAmount || 0}}件，已购{{good.intervalOrderCount || 0}}件</span>
									</div>
								</div>
							</div>
							</div>
					</div>

                <div :style="{ height: deliveryMode ? '120px' : '60px' }"></div>
                </div>

                <!-- 选择自提点后显示 -->
                <div
                    v-if="deliveryMode == 'sinceMention' && point"
                    class="p-1 text-warning font-12 position-fixed w-100"
                    style="background: #f8edc7; bottom: 50px; max-width: 750px"
                >
                    <div>
                        将前往
                        <span>{{ point.pointName }}</span>
                        自提，地址：
                        <span>{{ point.sinceMentionDetailAddr }}</span>
                    </div>
                </div>

                <!-- 汇总 -->
                <div class="submit-btn safearea-bb-white content-box" style="z-index: 99999;">
                    <div class="total-price">
                        合计：
                        <span class="price">
                            &#65509;
                            <em class="now">{{ Money(result.orderActualTotal)[0] }}</em>
                            .{{ Money(result.orderActualTotal)[1] }}
                        </span>
                    </div>
                    <a href="javascript:;" class="sub-btn" :class="{'but-pe-none': (!result || !result.orderGroupInfoBOS || !result.orderGroupInfoBOS.length)}" @click="subOrder" v-if="!submitOrder">提交订单</a>
                    <a href="javascript:;" class="sub-btn" @click="payTo" v-else>去支付</a>
                </div>
            </div>
            <!-- /提交订单 -->

            <!-- 选择快递方式 -->
            <div class="popup-hide" :class="{ show: showTransfeeDtos }">
                <div class="popup-box">
                    <div class="popup-tit">
                        <span class="tit">快递方式</span>
                        <i class="close close-pop" @click="closeTraansfee"></i>
                    </div>
                    <div class="popup-con post-way">
                        <div class="item" v-for="(item, index3) in currentTransfeeDtos" :key="`${index3} + feeDtos`" @click="choseTransprot(index3)">
                            <div class="item-txt">{{ item.desc }} {{ item.deliveryAmount }}</div>
                            <em class="choose" style="border-radius: 50%" :class="{ cur: item.checkSts }"></em>
                        </div>
                    </div>
                    <button class="popup-btn" @click="closeTraansfee">关闭</button>
                </div>
            </div>

            <!-- 选择优惠券 -->
            <div class="popup-hide" @click="showCoupon = false" :class="{ show: showCoupon }">
                <div class="popup-box">
                    <div class="popup-tit">
                        <span class="tit">选择优惠券和红包</span>
                        <i class="close close-pop" @click.stop="checkCoupon"></i>
                    </div>
                    <div class="popup-con use-coupons">
                        <div class="m-tabs">
                            <a href="javascript:;" class="item" :class="{ 'line-on': uncanUseCouponTrue }" @click.stop="uncanUseCouponTrue = true">
                                <span class="txt">
                                    可用
                                    <em class="s-txt" :style="{ color: themes.theme }">（{{ canUseCoupon.length ? canUseCoupon.length : 0 }}）</em>
                                </span>
                            </a>
                            <a href="javascript:;" class="item" :class="{ 'line-on': !uncanUseCouponTrue }" @click.stop="uncanUseCouponTrue = false">
                                <span class="txt">不可用</span>
                            </a>
                        </div>
                        <div>
                            <template v-if="uncanUseCouponTrue">
                                <div
                                    class="list-item"
                                    v-for="(item, canUseIndex) in canUseCoupon"
                                    :key="canUseIndex"
                                    @click.stop="changeCoupon(canUseIndex, item)"
                                >
                                    <div class="left">
                                        <div class="item-con">
                                            <div class="des" v-if="item.couponType == 'shop'">
                                                <i class="coupon-style">店铺</i>
                                                {{ item.couponName }}
                                            </div>
                                            <div class="des" v-if="item.couponType == 'product'">
                                                <i class="coupon-style">商品</i>
                                                {{ item.couponName }}
                                            </div>
                                            <span class="num" :style="{ color: themes.theme }">
                                                &#65509;
                                                <span class="price">{{ item.offPrice }}</span>
                                            </span>
                                        </div>
                                        <div class="condition">满{{ item.fullPrice }}元可用</div>
                                        <div class="use-time">
                                            使用日期：{{ item.getTime | dateformat('YYYY.MM.DD') }} - {{ item.endDate | dateformat('YYYY.MM.DD') }}
                                        </div>
                                    </div>
                                    <span class="choose" style="border-radius: 50%" :class="{ cur: item.select }"></span>
                                </div>
                            </template>
                        </div>
                        <template v-if="!uncanUseCouponTrue">
                            <div class="list-item not-use" v-for="(item, uncanIndex) in uncanUseCoupon" :key="uncanIndex">
                                <div class="left">
                                    <div class="item-con">
                                        <div class="des" v-if="item.couponType == 'shop'">
                                            <i class="coupon-style">店铺</i>
                                            {{ item.couponName }}
                                        </div>
                                        <div class="des" v-if="item.couponType == 'product'">
                                            <i class="coupon-style">商品</i>
                                            {{ item.couponName }}
                                        </div>
                                        <span class="num" :style="{ color: themes.theme }">
                                            &#65509;
                                            <span class="price">{{ item.offPrice }}</span>
                                        </span>
                                    </div>
                                    <div class="condition">满{{ item.fullPrice }}元可用</div>
                                    <div class="use-time">
                                        使用日期：{{ item.getTime | dateformat('YYYY.MM.DD') }}-{{ item.endDate | dateformat('YYYY.MM.DD') }}
                                    </div>
                                </div>
                                <span class="choose"></span>
                            </div>
                        </template>
                    </div>
                    <button class="popup-btn" @click.stop="checkCoupon">完成</button>
                </div>
            </div>
						
            <!-- 赠品 -->
            <div class="popup-hide" @click.stop :class="{ show: showPresents }">
                <div class="popup-box" style="bottom: 30px;">
                    <div class="popup-tit">
                        <template v-if="result.orderGroupInfoBOS">
                            <template v-if="result.orderGroupInfoBOS[groupIndex].promotionGroupCartList && result.orderGroupInfoBOS[groupIndex].promotionGroupCartList[promotionIndex]">
                                <div class="tit">
                                    选择赠品
                                    <span class="tit-span">（限领{{ result.orderGroupInfoBOS[groupIndex].promotionGroupCartList[promotionIndex].limitNumber }}件，领完为止）</span>
                                </div>
                                <i class="close close-pop" @click="showPresents = false"></i>
                            </template>
                        </template>
                    </div>

                    <div class="popup-con promotion-msg">
                        <template v-if="result.orderGroupInfoBOS">
                            <template v-if="result.orderGroupInfoBOS[groupIndex].promotionGroupCartList && result.orderGroupInfoBOS[groupIndex].promotionGroupCartList[promotionIndex]">
                                <template v-if="result.orderGroupInfoBOS[groupIndex].promotionGroupCartList[promotionIndex].presents">
                                    <div
                                        class="item"
                                        v-for="(item, presentsCarIndex) in result.orderGroupInfoBOS[groupIndex].promotionGroupCartList[promotionIndex].presents"
                                        :key="`presents + ${presentsCarIndex}`"
                                        @click="changeStatus(item, presentsCarIndex)"
                                    >
										<!-- 不是外部供应商的商品才可以选 -->
                                        <div v-if="!item.outPresent" class="item-con">
                                            <div class="gifts">
                                                <div class="gifts-img">
                                                    <img :src="$imgUrlHead + item.pic" alt="" />
                                                </div>
                                                <span class="gifts-txt">
                                                    <em v-if="item.stocks == 0" style="color: red">【已被领取完毕】</em>
                                                    {{ item.name }}
                                                </span>
                                                <span
                                                    class="choose"
                                                    style="border-radius: 50%"
                                                    :class="{ cur: item.checkStatus == 1 && item.stocks > 0 }"
                                                ></span>
                                            </div>
                                        </div>
                                    </div>
                                </template>
                            </template>
                        </template>
                    </div>
                </div>
            </div>
						<!-- 商品清单 -->
						<div class="popup-hide" @click.stop :class="{ show: showGoods }">
						    <div class="popup-box" style="padding-bottom: 44px;">
						        <div class="popup-tit flex-between">
						            <span class="font-14">商品清单</span>
												<span class="font-12 text-999">共{{goodsPopupList.prodNum}}件</span>
						        </div>
						
						        <div class="popup-con promotion-msg" style="padding-top: 0;">
											<div class="submit-order" style="margin: 0;">
												<div class="submit-list">
													<div class="submit-con" style="padding: 0;" v-for="(good, goodIndex) in goodsPopupList.list" :key="`goodsPopupList +  ${goodIndex}`">
													   <div class="pro-mes clearfix" style="padding: 0;">
													       <div class="pro-img" style="position: relative">
													           <legend-image :pic="good.pic" :options="{ w: '160', h: '160' }" :isJD="good.prodSource == 'JD'" />
													           <span class="type-tip" v-if="good.stocks == -1">商品地区限售</span>
													           <img src="@/assets/images/haitao-small.png" class="haitao" v-if="good.goodsType == 'overseas'" />
													       </div>
													       <div class="pro-name">
													           <a href="javascript:;" class="name">
													               <em v-if="good.joinDiscount" style="font-size: 10px" :style="{ color: themes.color }">【限时折扣】</em>
													               {{ good.prodName }}
													           </a>
													           <div class="sku">{{ good.cnProperties }}</div>
													   
													           <span class="price" :style="{ color: themes.color }" v-if="good.joinDiscount">
													               &#65509;
													               <em class="now" :style="{ color: themes.color }" style="font-size: 20px">{{ Money(good.discountPrice)[0] }}</em>
													               .{{ Money(good.discountPrice)[1] }}
													               <span style="text-decoration: line-through; color: #999; margin-left: 2px">
													                   ￥
													                   <em class="now" style="color: #999; font-size: 12px">{{ Money(good.price)[0] }}</em>
													                   .{{ Money(good.price)[1] }}
													               </span>
													           </span>
													   
													           <span class="price" :style="{ color: themes.color }" v-else>
													               &#65509;
													               <em class="now" :style="{ color: themes.color }">{{ Money(good.price)[0] }}</em>
													               .{{ Money(good.price)[1] }}
													           </span>
													       </div>
													       <div style="bottom: 0;" class="pro-num">×{{ good.basketCount }}</div>
													   </div>
													</div>
												</div>
											</div>
						            
						        </div>
										
										<div class="center-x bottom-0 popup-btn" @click="showGoods=false">我知道了</div>
						    </div>
						</div>
        </div>
    </div>
</template>

<script>
import legendImage from 'components/legendImage/legendImage'
import prodInfo from './components/prodInfo.vue'
import cash from 'utils/tool'
import { mapState } from 'vuex'
import { orderDetails, submitOrder, orderCouponsPageForApp, integralDeduct, userLastSinceMentionContact } from 'api/settlement'
import pay from 'service/pay'
let Decimal = require('decimal.js')

import formCheck from '@/utils/formCheck'

export default {
    data() {
        return {
            params: {
                //获取订单详情的对象
                selAdderessId: '', //地址id
                buyNow: '', //是否立即购买 false or true
                count: '', //数量
                prodId: '', //商品id
                shopCartItems: '', //购物车id集合
                skuId: '', //skuId
                type: '', //订单类型:NORMAL
                deliveryType: '', // 配送方式 merchantDelivery：商家配送，sinceMention：到店自提
                sinceMentionPointId: '' // 自提点id
            },
            previousIfo: {},
            result: {}, //获取到的全部信息
            Money: cash, //价格转换
            showTransfeeDtos: false, //显示快递
            currentTransfeeDtos: [], //当前的快递列表
            currTransNmae: '', //选择快递的商家
            transfeePrice: 0, //快递费
            couponPrice: 0, //优惠券优惠金额
            showCoupon: false, //显示选择优惠券
            remark: '', //买家留言
            canUseCoupon: [], //可使用优惠券
            uncanUseCoupon: [], //不可使用优惠券
            uncanUseCouponTrue: true, //显示可用优惠券
            userCouponId: '', //使用优惠券的id
            opType: '', //是否在使用优惠券
            switchInvoiceType: false, //默认不显示发票信息
						groupIndex: 0, //供应商分组index
						promotionIndex: 0, //供应商分组的活动index
            presentsIndex: '', //赠品索引值
            showPresents: false, //赠品弹窗
						showGoods: false, //商品清单
            submitOrder: false,
            checkedCoupon: '',
            promotionAmount: 0, //用来存优惠金额
            orderActualTotal: 0, //用来存总金额

            checked: false, // 是否使用积分
            integralOrderDeductInfo: {}, //积分抵扣订单金额信息

            overseasUserInfo: {}, //海涛身份信息

            // 自提
            showDelivery: false, // 自提点弹窗
            deliveryMode: '', // 配送方式 merchantDelivery：商家配送, sinceMention：到店自提
            phone: '', // 自提手机号码
            contextPerson: '', // 提货联系人
            formContextPerson: '', // 表单中的值
            formPhone: '', // 表单中的值
            point: '', // 提货点
            invoiceInfo: null, //发票信息
            invoiceTypeVal: null, //发票类型
            invoiceTitle: '', //发票抬头
            couponItem: '', // 优惠券(用于切换地址时缓存使用)
            couponIndex: null, // 优惠券index(用于切换地址时缓存使用)
            useIntegral: null, // 是否使用积分(用于切换地址时缓存使用)
            preRouter: '', // 上一个路由信息
            loadOrder: true, // 是否加载订单完成
			goodsPopupList: { //商品清单数据
				prodNum: 0,
				list: []
			}		
        }
    },
    components: {
        legendImage,
				prodInfo
    },
    // 进入路由前调用
    beforeRouteEnter(to, from, next) {
        // 保留上一个页面路由信息
        next((vm) => {
            vm.preRouter = { fullPath: from.fullPath }
        })
    },
    // 离开组件时调用
    beforeRouteLeave(to, from, next) {
        if (to.name == 'selfPoint') {
            // 缓存自提信息
            this.savePointInfo()
        }

        // 如果去选择地址 只有商家配送
        if (to.path == '/addressList') {
            // 缓存配送类型
            this.saveDeliveryType()
        }

        // 如果去发票
        if (to.path == '/invoice') {
            // 先判断是否到店自提
            if (this.deliveryType == 'sinceMention') {
                // 缓存自提信息
                this.savePointInfo()
                this.saveDeliveryType()
            } else {
                //    缓存配送类型
                this.saveDeliveryType()
            }
        }

        // 如果返回详情页，则清除相关缓存
        if (to.name == 'goodsDetail') {
            sessionStorage.removeItem('invoiceInfo')
            sessionStorage.removeItem('coupon')
            sessionStorage.removeItem('couponIndex')
            sessionStorage.removeItem('useIntegral')
            sessionStorage.removeItem('point')
        }

        next()
    },
    created() {
        // 如果缓存了上一个路由信息，则跳转回去
        if (sessionStorage.getItem('preRoute')) {
            const preRouter = JSON.parse(sessionStorage.getItem('preRoute'))
            sessionStorage.removeItem('preRoute')
            this.$router.go(-1)
            return
        }
    },
    mounted() {
        if (this.$route.query.shopCartItems) {
            this.params.shopCartItems = this.previousIfo.shopCartItems = this.$route.query.shopCartItems
        }

        if (this.$route.query.prodId) {
            this.params.prodId = this.$route.query.prodId
            this.previousIfo.prodId = this.$route.query.prodId
        }

        if (this.$route.query.count) {
            this.params.count = this.previousIfo.count = this.$route.query.count
        }

        this.params.activeId = this.$route.query.activeId ? this.$route.query.activeId : ''
        this.params.type = this.previousIfo.type = this.$route.query.type
        this.params.addNumber = this.previousIfo.addNumber = this.$route.query.addNumber ? this.$route.query.addNumber : ''
        this.params.buyNow = this.previousIfo.buyNow = this.$route.query.buyNow
        this.params.skuId = this.previousIfo.skuId = this.$route.query.skuId

        if (sessionStorage.getItem('remarkArr')) {
            this.remark = JSON.parse(sessionStorage.getItem('remarkArr'))
        }
        this.transfeePrice = 0

        // 获取提货点
        if (sessionStorage.getItem('point')) {
            this.point = sessionStorage.getItem('point') === 'undefined' ? '' : JSON.parse(sessionStorage.getItem('point'))

            this.$set(this.params, 'deliveryType', 'sinceMention')
            this.$set(this.params, 'sinceMentionPointId', this.point.id)
        }

        // 自提点的联系人/电话
        if (sessionStorage.getItem('selfPointData')) {
            const selfPointData = sessionStorage.getItem('selfPointData') === 'undefined' ? '' : JSON.parse(sessionStorage.getItem('selfPointData'))
            this.phone = selfPointData.phone
            this.contextPerson = selfPointData.contextPerson
            this.formPhone = selfPointData.phone
            this.formContextPerson = selfPointData.contextPerson
            sessionStorage.removeItem('selfPointData')
        }

        // 获取发票
        if (sessionStorage.getItem('invoiceInfo')) {
            this.invoiceInfo = JSON.parse(sessionStorage.getItem('invoiceInfo'))
            this.invoiceTypeVal = this.invoiceInfo.invoiceTypeVal
            this.invoiceTitle = this.invoiceInfo.titleInfo.invTitleType
        }
        // 获取配送类型缓存
        if (sessionStorage.getItem('deliveryType')) {
            this.$set(this.params, 'deliveryType', JSON.parse(sessionStorage.getItem('deliveryType')).deliveryType)
            sessionStorage.removeItem('deliveryType')
        }

        // 获取缓存的地址
        if (sessionStorage.getItem('addrId')) {
            this.params.selAdderessId = sessionStorage.getItem('addrId') === 'undefined' ? '' : sessionStorage.getItem('addrId')
        }

        // 缓存的优惠券
        if (sessionStorage.getItem('coupon')) {
            this.couponItem = sessionStorage.getItem('coupon') === 'undefined' ? '' : JSON.parse(sessionStorage.getItem('coupon'))
            this.couponIndex = sessionStorage.getItem('couponIndex') === 'undefined' ? '' : sessionStorage.getItem('couponIndex')
            sessionStorage.removeItem('coupon')
            sessionStorage.removeItem('couponIndex')
        }

        // 缓存的积分
        if (sessionStorage.getItem('useIntegral')) {
            this.useIntegral = sessionStorage.getItem('useIntegral') === 'undefined' ? '' : sessionStorage.getItem('useIntegral')
        }

        this.loadOrderDetails(this.params)
    },
    methods: {
				setIsShowAllPresents(groupIndex,promotionIndex) {
					let promotionGroupCart = this.result.orderGroupInfoBOS[groupIndex].promotionGroupCartList[promotionIndex]
					promotionGroupCart.isShowAllPresents = !promotionGroupCart.isShowAllPresents
					this.$set(this.result.orderGroupInfoBOS[groupIndex].promotionGroupCartList,promotionIndex, promotionGroupCart)
				},
				openGoodsPopup(val) {
					if(val.type === 'enableGroup') {
						this.goodsPopupList = {
							prodNum: this.result.orderGroupInfoBOS[val.groupIndex].prodNum,
							list: this.result.orderGroupInfoBOS[val.groupIndex].enableGroupCartList
						}
					}
					if(val.type === 'promotion') {
						this.goodsPopupList = {
							prodNum: this.result.orderGroupInfoBOS[val.groupIndex].promotionGroupCartList[val.promotionIndex].prodNum,
							list: this.result.orderGroupInfoBOS[val.groupIndex].promotionGroupCartList[val.promotionIndex].hitCartItems
						}
					}
					this.showGoods = true
				},
        getFocus() {
            window.scroll(0, 0)
        },

        //返回
        goback() {
            sessionStorage.removeItem('addrId')
            sessionStorage.removeItem('remarkArr')
            sessionStorage.removeItem('invoiceSession')
            this.$router.back()
            this.$router.isBack = true
        },

        //获取订单详情
        loadOrderDetails(params, couponFlag = true) {
            let that = this
            orderDetails(params)
                .then((res) => {
                    if (res.status == 1) {
                        that.result = res.result
                        that.promotionAmount = res.result.couponOffPrice
                        that.orderActualTotal = res.result.orderActualTotal
                        that.integralOrderDeductInfo = { ...that.integralOrderDeductInfo, ...res.result.integralOrderDeductInfo }
                        this.overseasUserInfo = res.result.overseasUserInfo
						// 便利循环找出每个供应商组的数量
						if(this.result.orderGroupInfoBOS) {
							this.result.orderGroupInfoBOS.forEach(val => {		 
								// 平台商品数量
								if(val.enableGroupCartList) {
									let prodNum = val.enableGroupCartList.reduce((total,val) => {
										return total + val.basketCount
									},0)
									val.prodNum = prodNum
								}
								// 活动商品数量
								if (val.promotionGroupCartList) {
									val.promotionGroupCartList.forEach(promotionVal => {
											let prodNum = promotionVal.hitCartItems.reduce((total,val) => {
												return total + val.basketCount
											},0)
											promotionVal.prodNum = prodNum
											// 有赠品的时候
											let selPresents = [] //作为已选到的字段，作为展示而已
											let outPresents = []
											if (promotionVal.presents) {
											    promotionVal.presents.forEach((presentsItem) => {
													if(presentsItem.checkStatus == 1) {
														selPresents.push(presentsItem)
													}
													if(presentsItem.outPresent) {
														outPresents.push(presentsItem)
													}
											    })
												//判断是否有内部商品且没有勾选的
												promotionVal.flag = promotionVal.presents.some((item) => item.checkStatus == 0 && !item.outPresent)
											}
											promotionVal.selPresents = selPresents
											promotionVal.outPresents = outPresents
											// 是否展示已选择的所有赠品 isShowAllPresents，如果可以选择2件以上就为flase，只有1件就为true
											promotionVal.isShowAllPresents = promotionVal.limitNumber === 1  ? true : false
									})
								}
							})
						}
												
												

                        if (this.remark) {
                            that.remark = this.remark
                        }

                        var transfeeDtos = that.result.transfeeDtos ? that.result.transfeeDtos : []
                        if (transfeeDtos && transfeeDtos.length) {
                            that.transfeePrice = that.transfeePrice + that.result.orderFreightAmount

                            transfeeDtos.forEach((element) => {
                                element.checkSts = false
                            })
                            transfeeDtos[0].checkSts = true
                        }

                        // 获取默认选中的配送方式
                        this.deliveryMode = res.result.deliveryTypeList.filter((item) => item.defaultType)[0].deliveryType
                        this.deliveryType = this.deliveryMode

                        if (this.deliveryMode == 'sinceMention') {
                            this.getsinceMentionInfo()
                        }

                        if (couponFlag) {
                            orderCouponsPageForApp({ type: that.previousIfo.type, couponId: this.couponItem.couponId }).then((res) => {
                                if (res.status == 1) {
                                    if (res.result) {
                                        that.canUseCoupon = res.result.usableUserCouponList ? res.result.usableUserCouponList : []
                                        that.uncanUseCoupon = res.result.disableUserCouponList ? res.result.disableUserCouponList : []
                                        // 判断有没有优惠券缓存，如果有，则重新计算优惠券
                                        if (this.couponItem) {
                                            this.changeCoupon(this.couponIndex, this.couponItem)
                                        }
                                        // 判断有没有使用积分缓存，如果有，则重新计算价格
                                        if (this.useIntegral) {

                                            // 这里加延迟器是后端要求加的，出了问题后端负责
                                            setTimeout(() => {
                                                integralDeduct({
                                                flag: true,
                                                type: this.params.type
                                            }).then((res) => {
                                                if (res.status != 1) {
                                                    this.$toast(res.msg)
                                                    this.checked = false
                                                    return
                                                }
                                                this.checked = true
                                                this.changePrice()
                                            })
                                            }, 500)
                                        }
                                    }
                                }
                            })
                        } else {
                            if (this.params.couponId) {
                                this.result.couponOffPrice = new Decimal(this.promotionAmount).add(new Decimal(this.couponPrice))
                            } else {
                                this.result.couponOffPrice = new Decimal(this.promotionAmount)
                            }

                            let orderTotalCash = new Decimal(this.result.orderTotalCash)
                                .sub(new Decimal(this.result.salesAmount))
                                .sub(new Decimal(this.result.shareSalesAmount)) // 减去分享金额
                                .sub(new Decimal(this.result.marketingAmount))
                                .sub(new Decimal(this.result.couponOffPrice))

                            this.calculateIntegralDeduct(orderTotalCash)
                            this.changePrice()
                        }
                    }
                })
                .finally((res) => {
                    this.loadOrder = false
                })
                .catch((error) => {
                })
        },

        // 获取最新下单的自提相关信息
        getsinceMentionInfo() {
            userLastSinceMentionContact()
                .then((res) => {
                    if (!res.success) return void this.$toast(res.msg)

                    if (res.result && !(this.phone && this.contextPerson)) {
                        this.phone = res.result.userContactPhone // 自提手机号码
                        this.contextPerson = res.result.userContactName // 提货联系人
                        this.formContextPerson = res.result.userContactName // 表单中的值
                        this.formPhone = res.result.userContactPhone // 表单中的值
                    }
                })
                .catch((err) => {
                })
        },

        //选择配送方式窗口弹出
        showTrans() {
            if (this.result.transfeeDtos.length > 0) {
                this.showTransfeeDtos = true
                this.currentTransfeeDtos = this.result.transfeeDtos
            }
        },

        // 是否使用积分
        changeIntegral(checked) {
            let params = {
                flag: checked,
                type: this.params.type
            }
            integralDeduct(params).then((res) => {
                if (res.status != 1) {
                    this.$toast(res.msg)
                    this.checked = false
                    return
                }
                this.checked = checked
                this.changePrice()
            })

            // 如果使用积分则缓存
            if (checked) {
                sessionStorage.setItem('useIntegral', '1')
                this.useIntegral = '1'
            }
        },

        //去选择发票
        goInvoice() {
            let remarkArr = []
            remarkArr = this.remark
            sessionStorage.setItem('remarkArr', JSON.stringify(remarkArr))
            //当有收获地址时
            if (this.deliveryMode !== 'sinceMention' && this.result.userAddress) {
                this.$router.push({
                    path: `/invoice`,
                    query: {
                        type: 0,
                        addrId: this.result.userAddress.addrId
                    }
                })
            } else {
                // 自提时
                this.$router.push({
                    path: `/invoice`,
                    query: {
                        type: 0
                    }
                })
            }
        },

        //选择快递
        choseTransprot(index) {
            this.transfeePrice = 0
            if (this.result.transfeeDtos && this.result.transfeeDtos.length) {
                for (var i = 0; i < this.result.transfeeDtos.length; i++) {
                    this.result.transfeeDtos[i].checkSts = false
                }

                if (this.result.transfeeDtos[index]) {
                    this.result.currentSelectTransfee = this.result.transfeeDtos[index]
                    this.result.transfeeDtos[index].checkSts = true
                    this.currTransNmae = this.result.transfeeDtos[index].desc
                    this.transfeePrice = this.result.transfeeDtos[index].deliveryAmount
                }
            }
            this.changePrice()
        },

        //选择赠品
        changeStatus(item, index) {
						// this.result.orderGroupInfoBOS[this.groupIndex].promotionGroupCartList[this.promotionIndex]
            let checkIndex = index
			let promotionGroupCart = this.result.orderGroupInfoBOS[this.groupIndex].promotionGroupCartList[this.promotionIndex]
            let limitNumber =promotionGroupCart.limitNumber //限制的数量
            if (item.stocks > 0) {
                let checkedNum = 0
               promotionGroupCart.presents.map((v) => {
                    if (v.checkStatus == 1 && item.skuId != v.skuId) {
                        //这边括号里要加一个判断 v不等于当前的item
                        checkedNum++
                    } // v.checkStatus == 0 ? 1 : 0
                })

                if (checkedNum == limitNumber) {
                    this.$toast(`限领${promotionGroupCart.limitNumber}件`)
                    return
                }
                item.checkStatus = item.checkStatus == 0 ? 1 : 0
								//过滤已选择的
								promotionGroupCart.selPresents = promotionGroupCart.presents.filter(val => {
									return val.checkStatus === 1
								})
								
								
                let flag = promotionGroupCart.presents.findIndex((v) => {
                    return v.checkStatus == 1
                })
                promotionGroupCart.flag = flag == -1 ? true : false
            } else {
                this.$toast('库存不足')
            }
        },
        //获取优惠券
        changeShowCoupon() {
            this.showCoupon = true
        },
        //改变优惠券
        checkCoupon() {
            this.showCoupon = false
        },
        openPresents(groupIndex,promotionIndex) {
            this.showPresents = true
						this.groupIndex = groupIndex
						this.promotionIndex= promotionIndex
            // this.presentsIndex = index
        },
				//去商品详情页
				goGoodsDetil(prodId) {
					this.$router.push({
					    path: `/goodsDetail`,
					    query: {
					        goodsInfoId: prodId
					    }
					})
				},
        //去切换地址
        goAddress() {
            let remarkArr = []
            remarkArr = this.remark
            sessionStorage.setItem('remarkArr', JSON.stringify(remarkArr))
            this.$router.push({
                path: `/addressList`,
                query: {
                    changeAddress: 1,
                    selectAddres: this.result.userAddress ? this.result.userAddress.addrId : ''
                }
            })
        },
        //关闭配送方法选择
        closeTraansfee() {
            this.showTransfeeDtos = false
        },

        //选择优惠券
        changeCoupon(index, item) {
            //单选可以，也可以去取消当前
            if (!this.canUseCoupon[index].select) {
                this.canUseCoupon.forEach((item, i) => {
                    if (i !== index) {
                        item.select = false
                    }
                })
            }

            this.canUseCoupon[index].select = !this.canUseCoupon[index].select

            this.params.couponId = item.select ? item.couponId : ''
            this.checkedCoupon = item.select ? item.couponName : ''
            this.couponPrice = item.select ? item.offPrice : -item.offPrice
            this.result.couponOffPrice = item.select
                ? new Decimal(this.promotionAmount).add(new Decimal(this.couponPrice))
                : new Decimal(this.result.couponOffPrice).add(new Decimal(this.couponPrice))

            //积分跟优惠券共用
            if (this.integralOrderDeductInfo.exclusiveCoupon || !this.checked) {
                //商品总金额
                let orderTotalCash = new Decimal(this.result.orderTotalCash)
                    .sub(new Decimal(this.result.salesAmount))
                    .sub(new Decimal(this.result.shareSalesAmount)) // 减去分享金额
                    .sub(new Decimal(this.result.marketingAmount))
                    .sub(new Decimal(item.select ? this.result.couponOffPrice : 0))
                this.calculateIntegralDeduct(orderTotalCash)
            }

            this.changePrice()
            orderCouponsPageForApp({ type: this.previousIfo.type, couponId: this.params.couponId }).then((res) => {
                if (res.status == 1) {
                    if (res.result) {
                        this.canUseCoupon = res.result.usableUserCouponList ? res.result.usableUserCouponList : []
                        this.uncanUseCoupon = res.result.disableUserCouponList ? res.result.disableUserCouponList : []
                    }
                }
            })

            // 获取新的优惠券index
            const newIndex = this.canUseCoupon.findIndex((item) => item.couponId == item.couponId)
            // 如果选中了优惠券，则缓存优惠券id
            if (item.select) {
                sessionStorage.setItem('coupon', JSON.stringify(item))
                sessionStorage.setItem('couponIndex', newIndex)
                this.couponItem = item
                this.couponIndex = index
            } else {
                // 没有选择优惠券则清除缓存
                sessionStorage.removeItem('coupon')
                sessionStorage.removeItem('couponIndex')
                this.couponItem = ''
                this.couponIndex = ''
            }
        },

        //计算积分抵扣
        calculateIntegralDeduct(orderTotalCash) {
            // 计算当前订单最高可抵扣金额 = 订单金额 * 订单最大抵扣金额比例
            let maxDeductAmount = new Decimal(orderTotalCash).mul(new Decimal(this.integralOrderDeductInfo.deductRate).div(100))
            // 计算当前订单所需抵扣积分 = 当前订单最高可抵扣金额 * 积分价值 ====>A
            let needIntegral = (this.integralOrderDeductInfo.availableIntegral = Math.floor(
                new Decimal(maxDeductAmount).mul(new Decimal(this.integralOrderDeductInfo.deducteIntegral))
            ))

            // 获取当前用户可用积分数量 如无积分记录则默认为0 ====>(B)
            let totalAvailableIntegral = new Decimal(this.integralOrderDeductInfo.totalAvailableIntegral) //  B

            // 判断用户总可用积分B >= 当前订单所需抵扣积分A 则扣减金额为A/积分价值 如果B < A 则扣减金额为B/积分价值

            // 积分抵扣金额 = 所需抵扣积分 / 积分价值
            if (totalAvailableIntegral >= needIntegral) {
                this.integralOrderDeductInfo.deductAmount = new Decimal(needIntegral).div(this.integralOrderDeductInfo.deducteIntegral).toNumber()
                this.integralOrderDeductInfo.availableIntegral = needIntegral
            } else {
                this.integralOrderDeductInfo.deductAmount = new Decimal(totalAvailableIntegral)
                    .div(this.integralOrderDeductInfo.deducteIntegral)
                    .toNumber()
                this.integralOrderDeductInfo.availableIntegral = totalAvailableIntegral
            }
            // this.integralOrderDeductInfo.deductAmount = needIntegral / this.integralOrderDeductInfo.deducteIntegral
        },

        // 计算价格
        changePrice() {
            let salesAmount = this.result.salesAmount //折扣金额
            let shareSalesAmount = this.result.shareSalesAmount //分享折扣金额
            let marketingAmount = this.result.marketingAmount //营销金额
            let promotionAmount = this.result.couponOffPrice //商品优惠价格
            let orderIntegralDeductAmount = this.checked ? this.integralOrderDeductInfo.deductAmount : 0 //积分抵扣
            var orderTotalCash = this.result.orderTotalCash //商品总金额
            var orderFreightAmount //商品运费
            this.transfeePrice ? (orderFreightAmount = this.transfeePrice) : (orderFreightAmount = this.result.orderFreightAmount)

            // 商品总价 = 商品总金额 - 分享折扣金额- 折扣金额 - 营销金额 - 积分抵扣 - 商品优惠价格  + 商品运费
            this.result.orderActualTotal = new Decimal(orderTotalCash)
                .sub(new Decimal(salesAmount))
                .sub(new Decimal(marketingAmount))
                .sub(new Decimal(promotionAmount))
                .sub(new Decimal(orderIntegralDeductAmount))
                .sub(new Decimal(shareSalesAmount))
                .add(new Decimal(orderFreightAmount))
        },

        //提交订单
        subOrder() {
			this.$utils.uDebounce(() => {
				const toast1 = this.$toast.loading({
				    mask: true,
				    message: '加载中...'
				})
				
				let params = {
				    presentList: '',
				    addrId: '',
				    couponId: '', //优惠券字符串
				    delivery: '', //配送方式
				    invoiceId: '', //发票id
				    payManner: 1, //支付方式  在线or货到
				    payTypeId: '', //支付类型ID
				    remark: '', //订单备注. shopId:备注
				    token: this.result.token, //token， 防止重复提交
				    type: this.params.type, //订单类型
				    channel: 'channel_micromall', //支付渠道
				    orderIntegralDeductAmount: this.integralOrderDeductInfo.deductAmount, //积分抵扣
				    // 添加自提点相关字段
				    mentionContactName: this.contextPerson,
				    mentionContactPhone: this.phone
				}
				
				let remarkTextList
				let regRule = /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g
				
				if (this.result.userAddress) {
				    params.addrId = this.result.userAddress.addrId
				}
				for (let i = 0; i < this.canUseCoupon.length; i++) {
				    if (this.canUseCoupon[i].select) {
				        params.couponId = this.canUseCoupon[i].couponId
				    }
				}
				
				if (!this.remark) {
				    this.remark = ''
				}
				remarkTextList = this.remark
				if (remarkTextList.match(regRule)) {
				    this.$toast('买家留言不支持表情')
				    return
				}
				
				if (!this.result.userAddress && this.deliveryMode == 'merchantDelivery') {
				    toast1.clear()
				    this.$toast('收货地址为空，请先填写收货地址')
				    return
				}
				
				if (!this.overseasUserInfo.realName && this.result.assemblyOrderType == 'OVERSEAS') {
				    this.$toast('此商品是海淘商品，需填写身份信息~~~')
				    return
				}
				
				// 如果时自提取货需要进行验证
				if (this.deliveryMode == 'sinceMention') {
				    if (!this.point) {
				        this.$toast('请选择提货点~')
				        return
				    }
				
				    if (!this.contextPerson) {
				        this.$toast('请填写提货联系人~')
				        return
				    }
				
				    if (!this.phone) {
				        this.$toast('请填写提货手机号码~')
				        return
				    }
				
				    if (!/^1[0-9][0-9]{9}$/.test(this.phone)) {
				        this.$toast('请填写正确的手机号码~')
				        return
				    }
				}
				
				//拼接活动赠品
				let presentsList = []
							let orderGroupInfoBOS = this.result.orderGroupInfoBOS
							orderGroupInfoBOS.forEach(bosVal => {
								if(bosVal.promotionGroupCartList) {
									bosVal.promotionGroupCartList.forEach((item, index) => {
									    let detail = {}
									    detail.activeId = item.id
									    let skuIds = []
									    let presents = item.presents
									    if (presents && presents.length > 0) {
									        presents.forEach((presentItem, presentIndex) => {
									            if (presentItem.checkStatus == 1 && presentItem.stocks > 0) {
									                skuIds.push(presentItem.skuId)
									            }
									        })
									    }
									    detail.skuIds = skuIds
									    presentsList.push(detail)
									})
								}
							})
				if (presentsList.length) {
				    params.presentList = JSON.stringify(presentsList)
				}
				params.remark = this.remark
				// 发票相关
				if (this.invoiceInfo) {
				    params.invType = this.invoiceInfo.invoiceType //发票类型
				    params.invAddress = this.invoiceInfo.invoiceInfo.invAddress //收票地址
				    params.invTitleId = this.invoiceInfo.titleInfo.id //抬头id
				    params.invPhone = this.invoiceInfo.invoiceMoblie ? this.invoiceInfo.invoiceMoblie : null //收票电话
				    params.invEmail = this.invoiceInfo.invoiceEmail ? this.invoiceInfo.invoiceEmail : null //收票邮箱
				    //如果类型为纸质，则需要收件人
				    if (this.invoiceInfo.invoiceType !== 'ORDINARY_INVOICE') {
				        params.invConsignee = this.invoiceInfo.invoiceInfo.invConsignee //发票收件人
				    }
				}
							
				submitOrder(params).then((res) => {
				    toast1.clear()
				    if (res.status == 1) {
				        sessionStorage.removeItem('addrId')
				        sessionStorage.removeItem('remarkArr')
				        sessionStorage.removeItem('coupon')
				        sessionStorage.removeItem('couponIndex')
				        sessionStorage.removeItem('useIntegral')
				        sessionStorage.removeItem('invoiceInfo')
				        sessionStorage.removeItem('point')
				        // 标记为已提交订单
				        this.submitOrder = true
				        sessionStorage.setItem('preRoute', JSON.stringify(this.preRouter))
				
				        this.payTo(res.result)
				    } else {
				        this.$toast(res.msg)
				    }
				})
			})
        },

        /**
         * 去支付
         */
        payTo(subNumber) {
            pay.orderPay(subNumber)
        },

        //去填写
        goIdentity() {
            this.$router.push({
                path: `/identity`,
                query: {
                    source: 'editor',
                    identityPicOpen: this.overseasUserInfo.identityPicOpen ? 1 : 0,
                    id: this.overseasUserInfo.id
                }
            })
        },

        // 切换配送方式
        changeDeliverMode(delivery) {
            this.deliveryType = delivery.deliveryType
            this.$set(this.params, 'deliveryType', delivery.deliveryType)
            this.loadOrderDetails(this.params, true)
        },

        // 选择自提点
        toSelectPoint() {
            this.$router.push({ name: 'selfPoint' })
        },
        // 缓存自提点联系人和联系电话
        savePointInfo() {
            sessionStorage.setItem(
                'selfPointData',
                JSON.stringify({
                    contextPerson: this.contextPerson,
                    phone: this.phone
                })
            )
        },
        // 缓存配送方式
        saveDeliveryType() {
            sessionStorage.setItem(
                'deliveryType',
                JSON.stringify({
                    deliveryType: this.deliveryType
                })
            )
        },

        // 查看税费说明
        checkDetail() {
            this.$dialog.alert({
                title: '税费说明',
                message: '税费已包含在商品价格内，付款时不额外增加费用',
                confirmButtonText: '我知道了'
            })
        },

        // 展示自提点弹窗
        showDialog() {
            this.showDelivery = true
        },

        // 关闭弹窗
        closeDialog() {
            this.showDelivery = false
        },

        // 确认自提信息
        submitInfo() {
            if (!this.formContextPerson) {
                this.$toast('请输入提货人')
                return
            }
            if (!this.formPhone) {
                this.$toast('请输入手机号')
                return
            }
            let errMsg = null
            errMsg = formCheck.phoneRight(this.formPhone, '请输入正确的手机号码')
            if (errMsg) {
                this.$toast(errMsg)
                return
            }

            this.contextPerson = this.formContextPerson
            this.phone = this.formPhone
            this.closeDialog()
        }
    },
    computed: {
        ...mapState(['themes']),
        ...mapState(['integralName'])
    }
}
</script>

<style src="@/assets/css/style/detail-style.css"></style>
<style src="@/assets/css/style/submit-order-style.css"></style>
<style src="@/assets/css/style/popup-style.css"></style>
<style src="@/assets/css/popup.css"></style>
<style src="@/assets/css/submit-order.css"></style>
<style src="@/assets/css/cart.css"></style>
<style scoped>
.pro-name {
    width: 75%;
}
.type-tip {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    font-size: 12px;
    background: rgba(78, 174, 49, 0.7);
    color: #fff;
    line-height: 20px;
    text-align: center;
}
.submit-order .submit-list .submit-con .gifts-mes {
    bottom: 5px;
}

.aaa.popup-hide.show {
    top: unset;
}

.bg-img {
    background: url('~@/assets/images/post-bg.png') -7px bottom repeat-x;
    background-size: 35px 3px;
}
</style>
